//
//  NSCharacterSet+RWAdditions.m
//  iconstruction-ios
//
//  Created by Ray on 2024/2/2.
//  Copyright © 2024 81SK. All rights reserved.
//

#import "NSCharacterSet+RWAdditions.h"

@implementation NSCharacterSet (RWAdditions)

- (NSString *)characterSetString {
    NSMutableArray *array = [NSMutableArray array];
    for (int plane = 0; plane <= 16; plane++) {
        if ([self hasMemberInPlane:plane]) {
            UTF32Char c;
            for (c = plane << 16; c < (plane+1) << 16; c++) {
                if ([self longCharacterIsMember:c]) {
                    UTF32Char c1 = OSSwapHostToLittleInt32(c); // To make it byte-order safe
                    NSString *s = [[NSString alloc] initWithBytes:&c1 length:4 encoding:NSUTF32LittleEndianStringEncoding];
                    [array addObject:s];
                }
            }
        }
    }
    return [array componentsJoinedByString:@""];
}

@end
